package com.petter.lock.juc;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author : GD
 * @date :2020/12/29 : 9:40
 */
public class ReentrantLockWaitMain {



    public static ReentrantLock lock = new ReentrantLock();
    private static int i = 0;

    public static class ReentrantLockThread implements Runnable{

        @Override
        public void run() {
            lock.lock();
            try {
                Thread.sleep(10000);
                System.out.println(i++);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }
    }

    public void runReentrantLockThread1(){
        for (int j = 0 ; j< 10000 ; j++) {
            new Thread(new ReentrantLockThread()).start();
        }
    }

    public static void main(String[] args) {
//       new ReentrantLockWaitMain().runReentrantLockThread1();
        new Thread(new ReentrantLockThread()).start();
        new Thread(new ReentrantLockThread()).start();
        new Thread(new ReentrantLockThread()).start();
    }
}
